import dataList from '@/components/dataList'
import {fetchList} from '../../api/finance-manage-fund-flow'
import fundExport from '../components/fund-export'
export default {
    components:{dataList,fundExport},
    provide() {
        return {
            initList: this.getListData,
        };
    },
    beforeMount() {
        this.getListData();
    },
    data(){
        return{
            tableData:[],
            // 请求参数
            params: {
                current: 1,
                size: 20,
                chargeProject: ''
            },
            // 分页
            pager: {
                total: 0, // 总页数
                current: 1, // 当前页数
                size: 20 // 每页显示多少条
            },
            // 页面loading
            loading: false,
            filterList: [
                { label: '费用周期', inputType: 'daterange', name: ['costPeriodStart','costPeriodEnd']},
                { label: '业务日期', inputType: 'daterange', name: 'businessDate'},
                { label: '收支类型', inputType: 'select', name: 'paymentType', multiple: true, children: [
                        {
                            label:'收入',
                            value: 0
                        },{
                            label:'支出',
                            value: 1
                        }
                    ]},
            ],
        }
    },
    methods:{
        getListData(params = {}) {
            this.loading = true
            let requestData = {...this.params, ...params}
            fetchList(requestData).then(res => {
                const  {current, size, total, records} = res.data.data
                this.tableData = records
                this.params = requestData
                this.pager = {total, current, size}
            }).finally(() => {
                this.loading = false
            })
        },
        download(){
            this.publicExport('资金流水','/api/financemanagefundflow/download',this.searchForm)
        },
        // 菜单点击监听
        handleMenuClick(type){
            switch (type) {
                case 'export':
                    this.download();
                    break;
                default:
                    this.$message(type)
                    break;
            }
        }
    },
    watch:{
        tableData(){
            for(let i=0;i<this.tableData.length;i++){
                this.tableData[i].costPeriodStart=this.tableData[i].costPeriodStart+'至'+this.tableData[i].costPeriodEnd
                if(this.tableData[i].paymentType==0){
                    this.tableData[i].paymentType="收入"
                }else{
                    this.tableData[i].paymentType="支出"
                }
            }
        }
    }

}
